{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 稀疏矩阵的线性代数"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "对于稀疏矩阵来说，其线性代数操作可以使用 `scipy.sparse.linalg` 实现："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import scipy.sparse.linalg"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 矩阵操作"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- `scipy.sparse.linalg.inv`\n",
    "    - 稀疏矩阵求逆\n",
    "- `scipy.sparse.linalg.expm`\n",
    "    - 求稀疏矩阵的指数函数"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 矩阵范数"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- `scipy.sparse.linalg.norm`\n",
    "    - 稀疏矩阵求范数"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 线性方程组求解"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "提供了一系列求解方法：\n",
    "http://docs.scipy.org/doc/scipy/reference/sparse.linalg.html#solving-linear-problems\n",
    "\n",
    "主要使用的是迭代方法求解。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 特征值分解和奇异值分解"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "对于特别大的矩阵，原来的方法可能需要太大的内存，考虑使用这两个方法替代：\n",
    "\n",
    "- `scipy.sparse.linalg.eigs`\n",
    "    - 返回前 k 大的特征值和特征向量\n",
    "- `scipy.sparse.linalg.svds`\n",
    "    - 返回前 k 大的奇异值和奇异向量"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## <font color=\"red\">所有的这些操作既可以在稀疏矩阵上使用，也可以在普通矩阵上使用。</font>"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
